home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / ucrasm27.zip / SOURCE.ZIP / STRREV.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  1KB  |  70 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7. ;
  8. ;
  9. ; strrev- reverses the characters in a string.
  10. ;
  11. ; inputs:
  12. ;
  13. ;    ES:DI- Points at the string to reverse.
  14. ;
  15. ;
  16. ; Created by Mike Blaszczak (.B ekiM)  8/8/90
  17. ; Some minor tweaking by R. Hyde 8/9/90
  18. ;
  19. ;
  20.         public    sl_strrev
  21. ;
  22. ;
  23. sl_strrev    proc    far
  24.         push    ds
  25.         push    si
  26.         push    di
  27.         push    ax
  28.         push    cx
  29.         pushf
  30.         cld
  31. ;
  32. ; Init ptr to the start of the string
  33. ;
  34.         mov    si, es
  35.         mov    ds, si
  36.         mov    si, di
  37. ;
  38. ; Compute the length of the string:
  39. ;
  40.         mov    cx, 0ffffh
  41.         mov    al, 0
  42.     repne    scasb
  43.         neg    cx
  44.         dec    cx
  45.         dec    cx
  46.         shr    cx, 1        ;Only have to do half the bytes.
  47.         jcxz    StrRvsd
  48.         dec    di             ;Point at zero byte.
  49. ;
  50. ; Okay, swap the bytes in the string.
  51. ;
  52. SwapBytes:    dec    di
  53.         lodsb
  54.         xchg    al, [di]    ;Note: es=ds.
  55.         mov    (0-1)[si], al
  56.         loop    SwapBytes
  57. ;
  58. StrRvsd:        popf
  59.         pop    cx
  60.         pop    ax
  61.         pop    di
  62.         pop    si
  63.         pop    ds
  64.         ret
  65. sl_strrev    endp
  66. ;
  67. ;
  68. stdlib        ends
  69.         end
  70.